/*
 * @Author: tianchunyu
 * @Date: 2020-05-06 11:09:16
 * @LastEditTime: 2020-05-06 19:19:18
 * @LastEditors: Please set LastEditors
 * @Description: offer wheel_s.h headfile ,api to outside
 * @FilePath: \X\app\xp\driver\wheel_s.h
 */
#ifndef __WHEEL_S_H
#define __WHEEL_S_H
#include "synron_ls_modbus.h"
#include<stdlib.h>

#define WHEEL_line_speed 0.5 //车轮的线速度，单位:m/s
#define WHEEL_MOTOR_REDUCE_RATIO (21)//减速比 电机和轮子之间的减速比
#define WHEEL_DIAMETER (0.184) //轮子直径
#define WHEEL_TURN_FAC (0.3)    //在停止或者行进过程 转弯的补偿差速与基本速度的比值 基本速度加减补偿速度造成速度差
#define WHEEL_SITU_ROTATE_SPEED (50)
#define SPEED_ABS_GRADE (13) //速度档位数组大小
#define SPEED_MAX_LIMIT (0.3)

/*
input singal defination 
*/
#define BOARD_ID         (1)   
#define INPUT_PIN_A      (1)   //向左电机输入信号引脚
#define INPUT_PIN_B      (2)   //向右电机输入信号引脚
#define HIGH_STATE       (1)   //输入信号高电平状态
#define LOW_STATE        (0)    // 输入信号低电平状态






#define WHEEL_left_fw   0     //左轮前进
#define WHEEL_left_bk   1     //左轮后退
#define WHEEL_right_fw  1     //右轮前进
#define WHEEL_right_bk  0     //右轮后退

/**********************type define***********************/
//wheel turn direction
typedef enum{
    wheel_left, //向左
    wheel_middle,   //中间
    wheel_right,    //向右
}WHEEL_turn;

//wheel object
typedef struct{
    u8 init;    //init state
    s8 dir;     //后退<0,停止=0，前进>0
    WHEEL_turn turn;    //turn direction
    s16 speed ; //电机转速 rmp
    float angle;   //行车角度
    SYNRO_handler *motor[2];    //motor object pointer
}WHEEL_object;


/**********************function extern********************/
extern int xp_wheel_init(u8 mode,u8 port,u32 speed); //wheel motor init
extern int xp_motor_run(u8 run,u8 dir); //wheel motor run
extern int xp_wheel_move(u8 speed_block,s8 dir);    //wheels move
extern int xp_wheel_turn(WHEEL_turn turn);  //wheel turn
extern int xp_wheel_round(WHEEL_turn turn,float angle); //wheel round a angle
extern int xp_wheel_get_speed(float line_speed);    //wheel get motor speed`
extern void xp_wheel_read_encode(void); //wheel motor read encode
extern int xp_wheel_debug(char *type,char *fun,char *param);
extern int xp_wheel_set_motors_speed(s16 motora_speed,s16 motorb_speed);
extern int xp_wheel_set_wheel_speed(float wheela_speed,float wheelb_speed);
extern int xp_wheel_set_motors_acc_timems(u16 time_ms);
extern int xp_wheel_set_motors_dcc_timems(u16 time_ms);
extern int xp_wheel_set_motors_acc_dcc_timems(u16 time_ms);
extern int xp_wheel_get_dir(void);  //get wheel dir
extern int xp_wheel_set_encode_specifice_value(s32 value);
extern int xp_wheel_get_left_encode();
extern int xp_wheel_get_right_encode();
extern int xp_wheel_motor_if_enble(SYNRON_TYPE if_enble);
extern int xp_wheel_get_enble_state();

/*
debug command list:
档位速度数组：
static u16 speed_grade[SPEED_ABS_GRADE] = {0,100,200,300,400,500,600,700,800,900,1000,1100,1200};

xp test
xp wheel init 轮子初始化
xp wheel move 20  停止 2档位速度
xp wheel move 21  前进 2挡速度
xp wheel move 22  后退 2挡速度
xp wheel rencode  读编码器的值
xp wheel round 0 原地左转
xp wheel round 2 原地右转
xp wheel round 1 原地不动

xp wheel turn 1 行进过程向  0 左 1中 2右
xp wheelms 200 200 设置轮子电机的转速 单位 rpm
xp wheelrs 1 1 设置机器人的行进速度












*/
#endif
